package entity.weapon;

import model.Model;

import org.lwjgl.util.vector.Vector3f;

import entity.MovingEntity;

/**
 * 
 * @author Jevgeni Krutov
 *
 */
public abstract class Shot extends MovingEntity {
	private long timeToLive;
	private int damage;

	public Shot(Vector3f position, Vector3f rotation, Model model, int w, int mass, int damage, long timeToLive) {
		super(position, rotation);
		setModel(model);
		
		setMass(mass);
		this.timeToLive = timeToLive;
		this.damage = damage;
	}
	
	@Override
	public void decreaseAwaitingTimes(long elapsedTime) {
		timeToLive = getDecreasedAwaitingTime(elapsedTime, timeToLive);
	}
	
	@Override
	public boolean isAlive() {
		return timeToLive != 0;
	}
	
	@Override
	public boolean isShot() {
		return true;
	}
	
	public void destroy() {
		timeToLive = 0;
	}
	
	@Override
	public void changeSpeedAndMove(long elapsedTime) {	
//		Vector3f v = new Vector3f(getSpeed());
//		setSpeed(v);
		
		//plus delta speed
		Vector3f deltaSpeed = new Vector3f(forcesSum);
		deltaSpeed.scale(0.01f / getMass());
		Vector3f.add(speed, deltaSpeed, speed);		
		
		forcesSum.set(0, 0, 0);
		addPosition(speed);
	}

	public int getDamage() {
		return damage;
	}
}
